<template>
	<view class="mine">
		<u-row gutter="50">
			<u-col span="12">
				<view class="headImg u-line u-flex">
					<view>
						<image  class="img" src="../../static/images/home_icon.png" mode=""></image>
					</view>
					<view class="text">
						<view>
							{{ mineData.username }}
						</view>
						<view>
							{{ mineData.phone }}
						</view>
					</view>
				</view>
				<u-cell-group border="false">
						<u-cell-item title="身份证号" :value="mineData.idCard" :arrow="false"></u-cell-item>
						<u-cell-item @click="phoneClick" title="修改手机号" ></u-cell-item>
						<u-cell-item @click="passwordClick" title="修改密码"></u-cell-item>
				</u-cell-group>
			</u-col>
		</u-row>
		<view class="butBack">
			<u-button class="but" type="primary" @click="signOut" shape="circle">退出登录</u-button>
		</view>
		<u-modal v-model="showModel" :content="content" show-cancel-button="true" confirm-color="#FFFFFF" @confirm="confirmClick" @cancel="cancelClick"></u-modal>
	</view>
</template>

<script>
	import { mapMutations } from 'vuex'
	export default {
		name: 'mine',
		data() {
			return {
				mineData: {},
				thumb: require('../../static/images/home_icon.png'),
				showModel: false ,// 弹框状态
				content: '是否退出登录?'
			}
		},
		created() {
			this.getMineData()
		},
		mounted() {
			// 身份证号中间四位隐藏
			//this.kcard = '37108319941116536'
			//this.kcard = this.kcard.replace(/^(.{7})(?:\d+)(.{7})$/,"$1****$2");
		},
		methods: {
			...mapMutations(['getTel']),
			// 获取个人信息
			getMineData() {
				let header = {
					"content-type":"application/x-www-form-urlencoded;charset=UTF-8"
				}
				this.$ajax.post({
					url: '/blade-user/info',
					header: header
				})
				.then(res => {
					// console.log(res)
					this.mineData = res.data
					// 存入vuex
					this.getTel(this.mineData.phone)
				})
			},
			// 跳转到修改手机号页面
			phoneClick() {
				this.$navJump.navigateTo('../../pageMine/modifyPhone')
			},
			// 跳转到修改密码页面
			passwordClick() {
				this.$navJump.navigateTo('../../pageMine/modifyPassword')
			},
			// 退出登录
			signOut() {
				this.showModel = true
			},
			// 退出登录--点击确认按钮
			confirmClick() {
				let header = {
					"content-type":"application/x-www-form-urlencoded;charset=UTF-8"
				}
				this.$ajax
					.get({
						url: '/blade-auth/oauth/logout',
						header: header
					})
					.then(res => {
						// console.log(res);
						uni.removeStorageSync('token'); // 清除缓存
						uni.setStorageSync('isUserTrue', 'false');
						this.showModel = false
						this.$navJump.redirectTo('../../pageLogin/login')
					});
				
			},
			// 退出登录--点击取消按钮
			cancelClick() {
				this.showModel = false
			}
		}
	}
</script>

<style lang="scss" scoped>
	.mine {
		margin-top: 25rpx;
		.headImg{
			background: #FFFFFF;
			padding: 26rpx 32rpx;
			.img {
				width: 80rpx;
				height: 80rpx;
				margin-right: 20rpx
			}
			.text {
				view:first-child {
					font-size: 30rpx;
					font-weight: 600;
					margin-bottom: 6rpx;
				}
				view:last-child {
					font-size: 26rpx;
					color: #999999;
				}
			}
		}
		.butBack {
			width: 90%;
			margin: 220rpx 5% 0;
			overflow: hidden;
			/deep/.u-btn--primary{
				background:linear-gradient(to right ,#3B85FE, #3BC0FE)!important
			}
		}
	}
	
	
</style>
